package com.atguigu.lease.web.admin.custom.converter;

import com.atguigu.lease.model.enums.ItemType;
import org.springframework.core.convert.converter.Converter;
import org.springframework.stereotype.Component;

/**
 * @Author：yyj
 * @Package：com.atguigu.lease.web.admin.custom.converter
 * @Project：project01
 * @name：StringToItemTypeConverter
 * @Date：2024/11/16 17:15
 * @Filename：StringToItemTypeConverter
 */

@Component
public class StringToItemTypeConverter implements Converter<String, ItemType> {
    @Override
    public ItemType convert(String source) {
        for (ItemType value : ItemType.values()) {
            if (value.getCode().equals(Integer.valueOf(source))){
                return value;
            }
        }
        throw new IllegalArgumentException("非法");
    }
}
